﻿
namespace HuaCheng.Model
{
    /// <summary>
    /// 常规工步的工步名拆分
    /// </summary>
    class CustomStep
    {
        //通道模式
        public int Model { get; set; }
        //通道波形
        public int Wave { get; set; }
        //充放电标志
        public bool Dir { get; set; }
        //参数设置类型
        public int Type { get; set; }
        public CustomStep Spilt(string stepName,string condiMode)
        {
            string sdir, smodel;
            CustomStep cs = new CustomStep();
            if(stepName == "搁置")
            {
                cs.Type = 9;
            }
            else if(stepName == "斜坡工况")
            {
                cs.Wave = 5;
                if(condiMode == "电流")
                {
                    cs.Type = 10;
                    cs.Model = 1;
                }
                else if (condiMode == "功率")
                {
                    cs.Type = 11;
                    cs.Model = 3;
                }               
            }
            else if (stepName == "脉冲工况")
            {
                cs.Wave = 4;
                if (condiMode == "电流")
                {
                    cs.Type = 12;
                    cs.Model = 1;
                }
                else if (condiMode == "功率")
                {
                    cs.Type = 13;
                    cs.Model = 3;
                }
            }            
            else
            {
                //如果为无波形的工步
                if (stepName == "恒阻放电" || stepName == "恒压恒流放电" || stepName == "恒压恒流充电")
                {
                    sdir = stepName.Substring(stepName.Length - 2, 2);
                    smodel = stepName.Substring(0, stepName.Length - 2);
                    //无波形默认为阶跃
                    cs.Wave = 1;
                    switch (stepName)
                    {
                        case "恒阻放电":
                            {
                                cs.Type = 1;
                            } break;
                        case "恒压恒流放电":
                        case "恒压恒流充电":
                            {
                                cs.Type = 2;
                            } break;
                    }
                }
                else
                {
                    smodel = stepName.Substring(0, stepName.Length - 4);
                    sdir = stepName.Substring(stepName.Length - 2, 2);
                    string swave = stepName.Substring(smodel.Length, stepName.Length - 2 - smodel.Length);
                    switch (swave)
                    {
                        case "阶跃":
                            {
                                cs.Wave = 1;
                                switch (smodel)
                                {
                                    case "恒流":
                                        {
                                            cs.Type = 3;
                                        } break;
                                    case "恒压":
                                        {
                                            cs.Type = 4;
                                        } break;
                                    case "恒功率":
                                        {
                                            cs.Type = 5;
                                        } break;
                                }
                            } break;
                        case "斜坡":
                            {
                                cs.Wave = 2;
                                switch (smodel)
                                {
                                    case "恒流":
                                        {
                                            cs.Type = 6;
                                        } break;
                                    case "恒压":
                                        {
                                            cs.Type = 7;
                                        } break;
                                }
                            } break;
                        case "脉冲":
                            {
                                cs.Wave = 3;
                                cs.Type = 8;
                            } break;
                    }
                }
                switch (smodel)
                {
                    case "恒流":
                        {
                            cs.Model = 1;
                        } break;
                    case "恒压":
                        {
                            cs.Model = 2;
                        } break;
                    case "恒功率":
                        {
                            cs.Model = 3;
                        } break;
                    case "恒压恒流":
                        {
                            cs.Model = 4;
                        } break;
                    case "恒阻":
                        {
                            cs.Model = 5;
                        } break;
                }
                switch (sdir)
                {
                    case "充电":
                        {
                            cs.Dir = false;
                        } break;
                    case "放电":
                        {
                            cs.Dir = true;
                        } break;
                }               
            }
            return cs;
        }
    }
}
